home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / akcl1615.lha / lsp / gprof.hc < prev    next >
Text File  |  1989-10-26  |  3KB  |  121 lines

  1. #define CF_FLAG (1 << 31) 
  2.  
  3. static
  4. /*
  5. mymonitor(low,high,x)
  6.      int low,high;
  7.      object x;
  8. { if (0 == x) {monitor(0); return 0;}
  9.   if (type_of(x)!=t_string) FEerror("expected string");
  10.   monitor(low,high,x->ust.ust_self,x->ust.ust_dim,1000);
  11. }
  12. */
  13. mymonitor(low,high,x,leng)
  14.      int low,high;
  15.      object x;
  16. { if (0 == x) {monitor(0); return 0;}
  17.   monitor(low,high,x,leng);
  18. }
  19.  
  20.  
  21. char *sbrk();
  22.  
  23. static
  24. mymonstartup(low,high)
  25. int low,high;
  26. {char *buf;
  27. buf = sbrk(0);
  28. monstartup(low,high);
  29. return buf;
  30. }
  31.  
  32. char *kcl_self;
  33.  
  34. #include <a.out.h>
  35. #include "../h/ext_sym.h"
  36. #define syment nlist
  37. #define fileheader exec
  38.  
  39. static char symname [200];
  40.  
  41.  
  42. static
  43. sym_leng_and_copy(ux,copy)
  44.      unsigned int ux;
  45.      int copy;
  46. { char *from;
  47.  int leng=0;
  48.  if (ux & CF_FLAG)
  49.    {object x = (object) (ux & ~CF_FLAG);
  50.     if (x->cf.cf_name ==0)
  51.        from="ZUNDEF";
  52.      else {leng = x->cf.cf_name->s.s_fillp;
  53.        from = x->cf.cf_name->s.s_self;}}
  54.  else if (ux) 
  55.    { from= (char *)(ux);}
  56.  else {from="UNDEF";}
  57.  if (leng==0) leng=strlen(from);
  58.  if (leng >= sizeof(symname)) FEerror("Too long symbol",0);
  59.  if(copy) bcopy(from,symname,leng);
  60.  symname[leng]='0';
  61.  return leng;
  62. }
  63.     
  64.  
  65.  
  66.      
  67.      
  68.        
  69.  
  70.  
  71. extern char *core_end;
  72.  
  73. static
  74. write_outsyms()
  75. {FILE *fdout,*fdin;
  76.  static struct syment sym;
  77.  struct fileheader hdr;
  78.  fdout= fopen("syms.out","w");
  79.  fdin=fopen(kcl_self,"r");
  80.  if (fdin == 0) FEerror("Can't find  akcl image");
  81.  fread(&hdr,sizeof(hdr),1,fdin);
  82.   if (fdout == 0) FEerror("Can't open syms.out");
  83.  fclose(fdin);
  84.  sym.n_type= (N_TEXT | N_EXT);
  85.  hdr.a_text=sizeof(hdr);
  86.  hdr.a_data=0;
  87.  hdr.a_bss=0;
  88.  hdr.a_trsize=0;
  89.  hdr.a_drsize=0;
  90.  hdr.a_syms= (1 + combined_table.length)*sizeof (struct syment);
  91.  fwrite(&hdr,sizeof(hdr),1,fdout);
  92.  fseek(fdout,N_SYMOFF(hdr),0);
  93.  {int i=0; int pos=4;
  94.   while (i < combined_table.length)
  95.     { /* printf("%d %d",i,SYM_STRING(combined_table,i));
  96.       fflush(stdout); */
  97.       
  98.       sym.n_un.n_strx = pos;
  99.       sym.n_value=SYM_ADDRESS(combined_table,i);
  100.       fwrite(&sym,sizeof(sym),1,fdout);
  101.       pos=pos+ sym_leng_and_copy(SYM_STRING(combined_table,i),1)+1;
  102. /*      printf("%s\n",symname); */
  103.       i++;
  104.     }
  105.  
  106.       sym.n_un.n_strx = pos;
  107.       sym.n_value=(int)core_end;
  108.       fwrite(&sym,sizeof(sym),1,fdout);
  109.       pos=pos+ strlen("_ENDSYM")+1;
  110.  
  111.  
  112.   fwrite(&pos,sizeof(pos),1,fdout);
  113.   for (i=0; i< combined_table.length ; i++)
  114.     {int leng=sym_leng_and_copy(SYM_STRING(combined_table,i),1);
  115.        fwrite(symname,leng,1,fdout);
  116.      putc(0,fdout);}
  117.    }
  118.  fwrite("_ENDSYM",8,1,fdout);
  119.  fclose(fdout);
  120. }
  121.